<template>
  <div v-if="isShow">
    <!-- 输入框 -->
    <div class="dialog_view">
      <!-- 头部 -->
      <div class="header">
        <div class="title">{{ title }}</div>
        <div class="close" @click="$emit('hidden')">x</div>
      </div>
      <!-- 主体 -->
      <div class="content">
        <!-- 插槽 -->
        <slot name="content"></slot>
        <!-- 尾部 -->
        <div class="footer">
          <slot name="footer">
            <button class="sui-btn btn-primary" @click="$emit('ensure')">{{ ensure }}</button>
            <button class="sui-btn btn-default" @click="$emit('cancel')">{{ cancel }}</button>
          </slot>
        </div>
      </div>
    </div>
    <!-- 遮罩 -->
    <div class="dialog_mask"></div>
  </div>
</template>

<script>
export default {
  name: 'Dialog',
  props: {
    isShow: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
    },
    cancel: {
      type: String,
      default: '取消',
    },
    ensure: {
      type: String,
      default: '确定',
    },
  },
}
</script>

<style lang="scss" scoped>
.dialog_mask {
  position: fixed;
  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 998;
}
.dialog_view {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  width: 500px;
  // height: 300px;
  background-color: white;
  border-radius: 4px;
  z-index: 999;
  .header {
    padding: 20px 20px 10px;
    .title {
      line-height: 24px;
      font-size: 18px;
      color: #303133;
    }
    .close {
      position: absolute;
      top: 20px;
      right: 20px;
      padding: 0;
      background: 0 0;
      border: none;
      outline: 0;
      cursor: pointer;
      font-size: 16px;
      color: #909399;
    }
  }
  .content {
    padding: 30px 20px;
    color: #606266;
    font-size: 14px;
    word-break: break-all;
    .footer {
      text-align: center;
      button {
        display: inline-block;
        padding: 2px 14px;
        box-sizing: border-box;
        margin-bottom: 0;
        font-size: 12px;
        line-height: 18px;
        text-align: center;
        vertical-align: middle;
        cursor: pointer;
        color: #333;
        background-color: #eee;
        border: 1px solid #e1e1e1;
        border-radius: 2px;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        line-height: 22px;
        font-size: 14px;
      }
      .btn-primary {
        color: #fff;
        background-color: #28a3ef;
        border: 1px solid #1299ec;
        margin-right: 10px;
      }
    }
  }
}
</style>
